Skip to content

Restore shared state after test fixtures - #23

Open
vinsymoyya wants to merge 1 commit into
google:masterfrom
vinsymoyya:fix/restore-test-fixture-state
Open

vinsymoyya wants to merge 1 commit into
google:masterfrom
vinsymoyya:fix/restore-test-fixture-state

Conversation

@vinsymoyya

Copy link
Copy Markdown

Restore process-wide state after test fixtures so unrelated tests can run in either module order. The response fixture replaced the standard threading.Lock; the inventory fixture left its fetch stub installed; TCLI fixtures leaked synchronization mocks, accessors, progress rendering, flag values, and module bindings.

Use scoped patchers and flag savers, preserve the shared FlagValues object's identity, and join the inventory fixture's worker before its class hook is restored. Move end-to-end inventory/accessor selection out of module import side effects and into its class fixture. Production code and existing assertions are unchanged.

Fixes #5.

Dedicated regressions run each of the four fixture lifecycles in a fresh process, check cleanup of shared resources, and exercise real threading afterward. All four fail against current master (f15c05543241e5faa482d0fae0c2244d456091b7) and pass with the fix.

Validation on Linux / Python 3.13:

  • All 99 tests pass in normal module order and all 99 pass with the test-module order reversed, including the canned-device end-to-end tests.
  • Pyink checks pass for the new regression module; git diff --check passes.
  • Tests run from container-local snapshots after a Windows bind-mounted collection attempt timed out; that timeout was not treated as a test result.
  • enterContext/enterClassContext are available throughout the package's declared Python range (>=3.11). No live device integration was run.

class FixtureIsolationTest(unittest.TestCase):

def assertFixtureIsolated(self, name):
result = subprocess.run(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is pretty involved and I'd rather avoid a subprocess if possible.

Either move the probe into a module or consider using pytest -p randomly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unittests are not independant

2 participants